package com.deductive.web.disposition.sw;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.deductive.common.core.controller.BaseController;
import com.deductive.common.core.domain.AjaxResult;
import com.deductive.common.core.page.TableDataInfo;
import com.deductive.domain.sw.DispositionSwWzqc;
import com.deductive.service.sw.DispositionSwWzqcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/hs-wzqc")
@Api(tags = "物质器材管理")
public class DispositionSwWzqcController extends BaseController {

    @Resource
    private DispositionSwWzqcService dispositionSwWzqcService;

    @PostMapping("/list")
    @ApiOperation("物质器材分页列表")
    public TableDataInfo list(@RequestBody DispositionSwWzqc wzqc) {
        startPage();
        LambdaQueryWrapper<DispositionSwWzqc> eq = new LambdaQueryWrapper<>();
        eq.eq(DispositionSwWzqc::getKind,wzqc.getKind());
        eq.like(StringUtils.isNotBlank(wzqc.getProductName()),DispositionSwWzqc::getProductName,wzqc.getProductName());
        List<DispositionSwWzqc> list = dispositionSwWzqcService.list(eq);
        return getDataTable(list);
    }

    @PutMapping("/update")
    @ApiOperation("物质器材修改")
    public boolean update(@RequestBody DispositionSwWzqc wzqc) {
        return dispositionSwWzqcService.updateById(wzqc);
    }

    @PostMapping("/insert")
    @ApiOperation("物质器材新增")
    public boolean insert(@RequestBody DispositionSwWzqc wzqc) {
        return dispositionSwWzqcService.save(wzqc);
    }

    @DeleteMapping
    @ApiOperation("物质器材删除")
    public AjaxResult delete(@RequestParam("idList") List<String> idList) {
        return AjaxResult.success(dispositionSwWzqcService.removeByIds(idList));
    }
}
